//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package org.jim.server.config;

import java.util.Objects;
import org.jim.core.ImHandler;
import org.jim.core.cache.redis.RedisConfig;
import org.jim.core.config.ImConfig;
import org.jim.core.config.ImConfig.Global;
import org.jim.core.http.HttpConfig;
import org.jim.core.listener.ImListener;
import org.jim.core.message.MessageHelper;
import org.jim.core.ws.WsConfig;
import org.jim.server.handler.DefaultImServerHandler;
import org.jim.server.handler.ImServerHandler;
import org.jim.server.handler.ImServerHandlerAdapter;
import org.jim.server.listener.DefaultImServerListener;
import org.jim.server.listener.ImServerListener;
import org.jim.server.listener.ImServerListenerAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tio.core.ssl.SslConfig;
import org.tio.server.ServerTioConfig;

public class ImServerConfig extends ImConfig {
    private static Logger log = LoggerFactory.getLogger(ImServerConfig.class);
    private ImServerHandler imServerHandler;
    private ImServerListener imServerListener;
    private MessageHelper messageHelper;
    private HttpConfig httpConfig;
    private WsConfig wsConfig;
    private RedisConfig redisConfig;
    public static String ON = "on";
    public static String OFF = "off";
    private String isStore;
    private String isCluster;
    private String isSSL;

    private ImServerConfig(ImServerHandler imServerHandler, ImServerListener imServerListener) {
        this.isStore = OFF;
        this.isCluster = OFF;
        this.isSSL = OFF;
        this.setImServerHandler(imServerHandler);
        this.setImServerListener(imServerListener);
        this.tioConfig = new ServerTioConfig(this.getName(), new ImServerHandlerAdapter(this.imServerHandler), new ImServerListenerAdapter(this.imServerListener));
        Global.set(this);
    }

    public static Builder newBuilder() {
        return new Builder();
    }

    public ImHandler getImHandler() {
        return this.getImServerHandler();
    }

    public ImListener getImListener() {
        return this.getImServerListener();
    }

    public ImServerListener getImServerListener() {
        return this.imServerListener;
    }

    public void setImServerHandler(ImServerHandler imServerHandler) {
        this.imServerHandler = imServerHandler;
        if (Objects.isNull(this.imServerHandler)) {
            this.imServerHandler = new DefaultImServerHandler();
        }

    }

    public void setImServerListener(ImServerListener imServerListener) {
        this.imServerListener = imServerListener;
        if (Objects.isNull(this.imServerListener)) {
            this.imServerListener = new DefaultImServerListener();
        }

    }

    public RedisConfig getRedisConfig() {
        return this.redisConfig;
    }

    public void setRedisConfig(RedisConfig redisConfig) {
        this.redisConfig = redisConfig;
    }

    public MessageHelper getMessageHelper() {
        return this.messageHelper;
    }

    public void setMessageHelper(MessageHelper messageHelper) {
        this.messageHelper = messageHelper;
    }

    public String getIsStore() {
        return this.isStore;
    }

    public void setIsStore(String isStore) {
        this.isStore = isStore;
    }

    public String getIsCluster() {
        return this.isCluster;
    }

    public void setIsCluster(String isCluster) {
        this.isCluster = isCluster;
    }

    public String getIsSSL() {
        return this.isSSL;
    }

    public void setIsSSL(String isSSL) {
        this.isSSL = isSSL;
    }

    public SslConfig getSslConfig() {
        return this.sslConfig;
    }

    public void setSslConfig(SslConfig sslConfig) {
        this.sslConfig = sslConfig;
        this.tioConfig.setSslConfig(sslConfig);
    }

    public HttpConfig getHttpConfig() {
        return this.httpConfig;
    }

    public void setHttpConfig(HttpConfig httpConfig) {
        this.httpConfig = httpConfig;
    }

    public WsConfig getWsConfig() {
        return this.wsConfig;
    }

    public void setWsConfig(WsConfig wsConfig) {
        this.wsConfig = wsConfig;
    }

    public ImServerHandler getImServerHandler() {
        return this.imServerHandler;
    }

    public static class Builder extends ImConfig.Builder<ImServerConfig, Builder> {
        private ImServerListener imServerListener;
        private MessageHelper messageHelper;
        private String isStore;
        private String isCluster;
        private String isSSL;
        private HttpConfig httpConfig;
        private WsConfig wsConfig;
        private RedisConfig redisConfig;

        public Builder() {
            this.isStore = ImServerConfig.OFF;
            this.isCluster = ImServerConfig.OFF;
            this.isSSL = ImServerConfig.OFF;
        }

        protected Builder getThis() {
            return this;
        }

        public Builder serverListener(ImServerListener imServerListener) {
            this.imServerListener = imServerListener;
            return this.getThis();
        }

        public Builder messageHelper(MessageHelper messageHelper) {
            this.messageHelper = messageHelper;
            return this.getThis();
        }

        public Builder isStore(String isStore) {
            this.isStore = isStore;
            return this.getThis();
        }

        public Builder isCluster(String isCluster) {
            this.isCluster = isCluster;
            return this.getThis();
        }

        public Builder isSSL(String isSSL) {
            this.isSSL = isSSL;
            return this.getThis();
        }

        public Builder httConfig(HttpConfig httpConfig) {
            this.httpConfig = httpConfig;
            return this.getThis();
        }

        public Builder wsConfig(WsConfig wsConfig) {
            this.wsConfig = wsConfig;
            return this.getThis();
        }

        public Builder redisConfig(RedisConfig redisConfig) {
            this.redisConfig = redisConfig;
            return this.getThis();
        }

        public ImServerConfig build() {
            ImServerConfig imServerConfig = new ImServerConfig(new DefaultImServerHandler(), this.imServerListener);
            imServerConfig.setBindIp(this.bindIp);
            imServerConfig.setBindPort(this.bindPort);
            imServerConfig.setReadBufferSize(this.readBufferSize);
            imServerConfig.setMessageHelper(this.messageHelper);
            imServerConfig.setIsStore(this.isStore);
            imServerConfig.setIsCluster(this.isCluster);
            imServerConfig.setIsSSL(this.isSSL);
            imServerConfig.setSslConfig(this.sslConfig);
            imServerConfig.setCluster(this.cluster);
            imServerConfig.setHttpConfig(this.httpConfig);
            imServerConfig.setWsConfig(this.wsConfig);
            imServerConfig.setHeartbeatTimeout(this.heartbeatTimeout);
            imServerConfig.setImGroupListener(this.imGroupListener);
            imServerConfig.setImUserListener(this.imUserListener);
            imServerConfig.setRedisConfig(this.redisConfig);
            return imServerConfig;
        }
    }
}
